"""
    定义在字符串变量
        字符串变量= "字符..."
        字符串变量= '字符...'

    他说："python很简单"

    *长度 len(字符串变量)
    *每个字符都有下标 下标从0开始
    *切片操作
        变量[起始位置:结束位置:步长]
"""
str1 = '他说："python很简单"'
str2 = "他的外号叫'小猪'"
str3 = '''
个人信息存储，personInfo = “我是一只来自北方的猫”
产品信息存储，productInfo = “这个是一个没有用的商品”
都需要字符串来存储
'''

print(len(str1))
print(len(str2))
print(len(str3))
print(str2[6],str2[7])

print(str1[4:13:])
print(str2[6:8:])
print(str1[0:len(str1):2])
print(str1[::2])
print(str1[:3:])
print(str1[3::])
print(str1[::-1])

# 查找字符串
# find index  count
print(str1.find("python")) # 存在返回下标
print(str1.find("python1")) # 不存在 返回-1
print(str1.index("python")) # 村则返回下标
# print(str1.index("python1")) ValueError: substring not found
print(str3.count("w"))

# replace
str4 = "祖国大好河山，人人爱"

str5 = str4.replace("河山","山河")
print(str4)
print(str5)

# split 分割
str5 ="小黄，小白，小刘"
names = str5.split("，")
print(names)

#
print(str4.startswith("祖国"))
print(str4.endswith("人人爱"))

keyword =" 铅  笔 "
print(keyword.strip())
print(keyword.lstrip())
print(keyword.rstrip())
print(keyword.replace(" ",""))
astr = "abc发啊啊"
print(str5.isalpha())
print(astr.isalpha())
print(astr.isdigit())
bstr = "10000"
print(bstr.isdigit())
print(bstr.isalnum())
print(keyword.isalnum())

# 5.1.输入一段数字和字母组合，判断数字和字母各有多少个
strX = input("请输入一个字符串")
numCount = 0
charCount = 0
for x in strX:
    if x.isdigit():
        numCount += 1
    if x.isalpha():
        charCount += 1
print("字母出现的次数为{}，数字出现的次数为{}".format( charCount,numCount))

strY = "aaa121212aaasdfdfshjjk4454"

i = strY.find("a")

while i >=0:
    print(i)
    i = strY.find("a", i+1)